<?php

namespace app\http\middleware;

use think\facade\Session;
use think\Response;
use think\Request;

class CheckAdmin
{
    public function handle(Request $request, \Closure $next)
    {
        $admin_id = Session::get('admin_id');
        if (!$admin_id) {
            if($request->isAjax()){
                return Response::create(['code' => 1, 'msg' => '登录失效'], 'json');
            }else{
                return Response::create('index/login', 'redirect', 302);
            }
        } else {
            return $next($request);
        }
    }
}